﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Cells;
using HCCommon;
using HCMessage.Model;

namespace HCBusiness
{
   public class ExportReportExcel
    {
        private Workbook _workbook;
        private Worksheet _BOARates;
        private readonly string _cStyleTitleRight = "sTitleRight";
        private readonly string _cStyleTitleLeft = "sTitleLeft";
        private readonly string _cStyleTitleCenter = "sTitleCenter";

        private readonly string _cStyleCurrency = "sCurrency";
        private readonly string _cStyleDateTime = "sDateTime";
        private readonly string _cStyleString = "sString";

        public void ExportExcel(ItemReport itemReport)
        {
            DateTime startDate = DateTime.Today.AddDays(-30);
            DateTime endDate = DateTime.Today;
            //PageMode = PageModeValues.Hide;
            string _outputFileName;

            _workbook = new Workbook();
            AsposeLicense.SetCellsLicenses();

            Aspose.Cells.Style style = _workbook.Styles[_workbook.Styles.Add()];
            style.Name = _cStyleTitleRight;
            style.Font.Name = "Arial";
            style.Font.Size = 10;
            style.Font.IsBold = true;
            style.Font.Color = System.Drawing.Color.White;
            style.ForegroundColor = System.Drawing.Color.Black;
            style.Pattern = BackgroundType.Solid;
            style.HorizontalAlignment = TextAlignmentType.Right;


            style = _workbook.Styles[_workbook.Styles.Add()];
            style.Name = _cStyleTitleLeft;
            style.Font.Name = "Arial";
            style.Font.Size = 10;
            style.Font.IsBold = true;
            style.Font.Color = System.Drawing.Color.White;
            style.ForegroundColor = System.Drawing.Color.Black;
            style.Pattern = BackgroundType.Solid;
            style.HorizontalAlignment = TextAlignmentType.Left;

            style = _workbook.Styles[_workbook.Styles.Add()];
            style.Name = _cStyleTitleCenter;
            style.Font.Name = "Arial";
            style.Font.Size = 10;
            style.Font.IsBold = true;
            style.Font.Color = System.Drawing.Color.White;
            style.ForegroundColor = System.Drawing.Color.Black;
            style.Pattern = BackgroundType.Solid;
            style.HorizontalAlignment = TextAlignmentType.Center;


            style = _workbook.Styles[_workbook.Styles.Add()];
            style.Name = _cStyleCurrency;
            style.Font.Name = "Arial";
            style.Font.Size = 10;
            style.Number = 4;

            style = _workbook.Styles[_workbook.Styles.Add()];
            style.Name = _cStyleDateTime;
            style.Font.Name = "Arial";
            style.Font.Size = 10;
            style.Number = 14;

            style = _workbook.Styles[_workbook.Styles.Add()];
            style.Name = _cStyleString;
            style.Font.Name = "Arial";
            style.Font.Size = 10;
            style.Number = 0;


            foreach (var r in itemReport.EnvCtList)
            {
                
            }

        }


        private void WriteTitleRow(int row, int column, string value, string type,Worksheet sheet)
        {
            sheet.Cells[row, column].PutValue(value);
            switch (type)
            {
                case "Currency":
                    sheet.Cells[row, column].SetStyle(_workbook.Styles[_cStyleTitleRight]);
                    break;

                default:
                    sheet.Cells[row, column].SetStyle(_workbook.Styles[_cStyleTitleCenter]);
                    break;
            }

        }

        private void WriteRow(int row, int column, object value, Type type, Worksheet sheet)
        {
            switch (type.Name)
            {
                case "DateTime":
                    var dt = new DateTime();
                    if (DateTime.TryParse(value.ToString(), out dt))
                    {
                        sheet.Cells[row, column].PutValue(dt.ToShortDateString());
                        sheet.Cells[row, column].SetStyle(_workbook.Styles[_cStyleDateTime]);
                    }
                    break;
                case "Decimal":
                    decimal val = default(decimal);
                    if (decimal.TryParse(value.ToString(), out val))
                    {
                        sheet.Cells[row, column].PutValue(val);
                        sheet.Cells[row, column].SetStyle(_workbook.Styles[_cStyleCurrency]);
                    }
                    break;
                default:
                    sheet.Cells[row, column].PutValue(value);
                    sheet.Cells[row, column].SetStyle(_workbook.Styles[_cStyleString]);
                    break;
            }
        }
    }
}
